package nowcoder.hw.hj08;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String ns = reader.readLine();
        SortedMap<Integer, Integer> res = new TreeMap<>();
        int n = Integer.valueOf(ns);
        while (n-- > 0) {
            String[] mapping = reader.readLine().split(" ");
            Integer key = Integer.valueOf(mapping[0]);
            Integer val = Integer.valueOf(mapping[1]);
            res.put(key, res.getOrDefault(key, 0) + val);
        }
        StringBuilder stringBuilder =new StringBuilder();
        res.forEach((k, v) -> {
            stringBuilder.append(k + " " + v).append("\n");
        });
        stringBuilder.deleteCharAt(stringBuilder.length()-1);
        System.out.println(stringBuilder);
    }
}
